// API配置
export const getApiBaseUrl = (): string => {
  // 如果是开发环境且在本地访问，使用localhost
  if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
    return "http://localhost:3000/api";
  }

  // 如果是通过IP访问（手机端），使用对应的IP
  if (location.hostname === "192.168.1.103") {
    return "http://192.168.1.103:3000/api";
  }

  // 默认使用当前域名的3000端口
  return `http://${location.hostname}:3000/api`;
};

export const API_BASE_URL = getApiBaseUrl();

// 用于上传文件的基础URL
export const getUploadBaseUrl = (): string => {
  if (location.hostname === "localhost" || location.hostname === "127.0.0.1") {
    return "http://localhost:3000";
  }

  if (location.hostname === "192.168.1.103") {
    return "http://192.168.1.103:3000";
  }

  return `http://${location.hostname}:3000`;
};

export const UPLOAD_BASE_URL = getUploadBaseUrl();
